/*
 * @Author: szx
 * @Date: 2022-04-22 12:50:30
 * @LastEditTime: 2022-04-22 13:01:00
 * @Description:
 * @FilePath: \leetcode\300-399\396\396.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var maxRotateFunction = function (nums) {
    let f = nums.reduce((a, b, i) => a + b * i, 0),
        n = nums.length,
        sum = nums.reduce((a, b) => a + b);
    let res = f;
    for (let i = n - 1; i > 0; i--) {
        f += sum - n * nums[i];
        res = Math.max(res, f);
    }
    return res;
};
console.log(maxRotateFunction([4, 3, 2, 6]));
